home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // Copyright (c) 2002, Colin Granville
- //
- // All rights reserved.
- //
- // Redistribution and use in source and binary forms, with or
- // without modification, are permitted provided that the following
- // conditions are met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- //
- // * Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following
- // disclaimer in the documentation and/or other materials
- // provided with the distribution.
- //
- // * The name Colin Granville may not be used to endorse or promote
- // products derived from this software without specific prior
- // written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- // OF THE POSSIBILITY OF SUCH DAMAGE.
- //
- //--------------------------------------------------------------------------
-
- #ifndef GuiGadget_h
- #define GuiGadget_h
-
- #include "GuiWindow.h"
-
- void set_component_string(GuiObjectId,GuiComponentId,int method_code,const char* str);
- string get_component_string(GuiObjectId,GuiComponentId,int method_code,int item=0);
- void set_component_value(GuiObjectId ob_id,GuiComponentId comp_id,int method_code,int value);
- int get_component_value(GuiObjectId ob_id,GuiComponentId comp_id,int method_code);
-
- // GuiToolboxGadget generic flags
- #define GuiToolboxGadget_Faded (1u<<31)
- #define GuiToolboxGadget_AtBack (1u<<30)
-
- class GuiToolboxGadget
- {
- protected: // placed here so that they are inlined
- int getCompValue(int method_code) const
- {return get_component_value(m_window_id,m_component_id,method_code);}
- void setCompValue(int method_code,int value)
- {set_component_value(m_window_id,m_component_id,method_code,value);}
- void getCompStruct(int method_code,void* str) const
- {set_component_value(m_window_id,m_component_id,method_code,(int)str);}
- void setCompStruct(int method_code,const void* str)
- {set_component_value(m_window_id,m_component_id,method_code,(int)str);}
- string getCompString(int method_code,int item=0) const
- {return get_component_string(m_window_id,m_component_id,method_code,item);}
- void setCompString(int method_code,const char* str)
- {set_component_string(m_window_id,m_component_id,method_code,str);}
-
- public:
- enum {SwiChunkBase = 0x82880};
- GuiToolboxGadget(GuiWindow& window, GuiComponentId cid);
- unsigned int getFlags() const {return getCompValue(64);}
- void setFlags(unsigned int new_flag_settings) {setCompValue(65,new_flag_settings);}
- void fade(bool fade);
-
- void setHelpMessage(const char* message_text) {setCompString(66,message_text);}
- string getHelpMessage() const {return getCompString(67);}
-
- void setFocus() {setCompValue(69,0);}
- int getType() const {return getCompValue(70);}
- void move(const GuiBBox& box) {setCompStruct(71,&box);}
- void getBBox(GuiBBox& box) const {getCompStruct(72,&box);}
-
- GuiObjectId windowId() const {return m_window_id;}
- GuiComponentId componentId() const {return m_component_id;}
- bool contains(int wimp_handle,int icon_handle);
-
- private:
- GuiObjectId m_window_id;
- GuiComponentId m_component_id;
-
- void operator=(); //no copying - not defined
- GuiToolboxGadget(const GuiToolboxGadget&); //no copying - not defined
- };
-
- //*************************************************************************
- // GADGETS
- //*************************************************************************
-
- class GuiActionButton : public GuiToolboxGadget
- {
- public:
- GuiActionButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
- };
-
- //*************************************************************************
-
- class GuiAdjuster : public GuiToolboxGadget
- {
- public:
- GuiAdjuster(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- enum {Increment=1<<0,UpDown=1<<1}; //flags
-
- class Clicked : public GuiToolboxEventHeader
- {
- public:
- enum {Event = GuiToolboxGadget::SwiChunkBase+12};
- int direction;
- bool isDown() {return direction==0;}
- };
- };
-
- //*************************************************************************
-
- class GuiButton : public GuiToolboxGadget
- {
- public:
- GuiButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- void setValue(const char* value) {setCompString(962,value);}
-
- };
-
- //*************************************************************************
-
- class GuiDisplayField : public GuiToolboxGadget
- {
- public:
- GuiDisplayField(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- void setValue(const char* value) {setCompString(448,value);}
- string getValue() const {return getCompString(449);}
- };
-
- //*************************************************************************
-
- class GuiLabel : public GuiToolboxGadget
- {
- public:
- GuiLabel(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
- };
-
- //*************************************************************************
-
- class GuiNumberRange : public GuiToolboxGadget
- {
- public:
- GuiNumberRange(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- void setValue(int value) {setCompValue(832,value);}
- int getValue() const {return getCompValue(833);}
- };
-
- //*************************************************************************
-
- class GuiOptionButton : public GuiToolboxGadget
- {
- public:
- GuiOptionButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- void set(bool on) {setCompValue(196,(on)?1:0);}
- bool isOn() const {return getCompValue(197);}
- };
-
- //*************************************************************************
-
- class GuiRadioButton : public GuiToolboxGadget
- {
- public:
- GuiRadioButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- void select() {setCompValue(388,1);}
- bool isSelected() const {return getCompValue(389);}
- GuiComponentId getSelected() const;
- };
-
- //*************************************************************************
-
- class GuiSlider : public GuiToolboxGadget
- {
- public:
- GuiSlider(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- void setValue(int value) {setCompValue(576,value);}
-
- enum {SetUpper=1<<0,SetLower=1<<1,SetStepSize=1<<2};
- void setBounds(int flags,int lower_bound,int upper_bound,int step_size);
-
- class ValueChanged : public GuiToolboxEventHeader
- {
- public:
- enum {Event = GuiToolboxGadget::SwiChunkBase+6};
- enum {DragStart=0,DragInProgress=2,DragEnded=1};//flags - different form book
- int newValue;
- };
- };
-
- //*************************************************************************
-
- class GuiToolAction : public GuiToolboxGadget
- {
- public:
- enum {SwiChunkBase=0x140140};
- GuiToolAction(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
- void set(bool on) {setCompValue(SwiChunkBase+6,(on)?1:0);}
- };
-
- //*************************************************************************
-
- class GuiWritableField : public GuiToolboxGadget
- {
- public:
- GuiWritableField(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
-
- void setValue(const char* value) {setCompString(512,value);}
- string getValue() const {return getCompString(513);}
- };
-
-
- #endif
-